home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / System / DX Clock 1.31 / DX Clockƒ / PopMenus2.p < prev    next >
Encoding:
Text File  |  1994-01-05  |  3.7 KB  |  157 lines  |  [TEXT/PJMM]

  1. unit PopMenus2;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Tools;
  7.  
  8.     type
  9.         PopMenu2 = record
  10.                 menuH: MenuHandle;                    { ID of the menu                }
  11.                 titleRect,                             { Rectangle of title     }
  12.                 menuRect: Rect;                     { Rectangle of menu     }
  13.                 last: Integer                         { last item selected     }
  14.             end;
  15.  
  16.     procedure NewPopUp2 (var theMenu: MenuHandle; var thePopMenu: PopMenu2; curItem: Integer; box: Rect);
  17.     function PopSelect2 (var theMenu: PopMenu2): Integer;
  18.     procedure UpdateMenu2 (theMenu: PopMenu2; drawTitle: Boolean);
  19.  
  20. implementation
  21.  
  22. {----------------------------------------------}
  23.  
  24.     procedure NewPopUp2 (var theMenu: MenuHandle; var thePopMenu: PopMenu2; curItem: Integer; box: Rect);
  25.  
  26. { Create the popup and initialize the record. }
  27.  
  28.         var
  29.             oldStyle: Style;
  30.             titleLen, oldSize, oldFont: Integer;
  31.             theInfo: FontInfo;
  32.             curPort: GrafPtr;
  33.             theTitle: str255;
  34.  
  35.     begin
  36.  
  37.         GetPort(curPort);
  38.         oldFont := curPort^.txFont;
  39.         oldSize := curPort^.txSize;
  40.         oldStyle := curPort^.txFace;
  41.         TextFont(0);
  42.         TextSize(0);
  43.         TextFace([]);
  44.         with thePopMenu do
  45.             begin
  46.                 menuH := theMenu;
  47.                 last := curItem;
  48.                 InsertMenu(menuH, -1);
  49.                 HLock(Handle(menuH));
  50.                 theTitle := menuH^^.menuData;
  51.                 titleLen := StringWidth(theTitle) + 3;
  52.                 GetFontInfo(theInfo);
  53.                 with theInfo, box do
  54.                     SetRect(menuRect, left + titleLen, top, left + titleLen + menuH^^.menuWidth, top + ascent + descent + leading);
  55.                 if (menuRect.right > box.right) then
  56.                     menuRect.right := box.right;
  57.                 with box do
  58.                     SetRect(titleRect, left - 5, top, left + titleLen, menuRect.bottom);
  59.                 HUnlock(Handle(menuH));
  60.             end;
  61.         TextFont(oldFont);
  62.         TextSize(oldSize);
  63.         TextFace(oldStyle);
  64.  
  65.     end; { NewPopUp2 }
  66.  
  67. {----------------------------------------------}
  68.  
  69.     procedure UpdateMenu2 (theMenu: PopMenu2; drawTitle: Boolean);
  70.  
  71.         var
  72.             theRect: Rect;
  73.             theStr: Str255;
  74.             oldStyle: Style;
  75.             oldSize, oldFont: Integer;
  76.             theInfo: FontInfo;
  77.             curPort: GrafPtr;
  78.             theStyle: Style;
  79.  
  80.     begin
  81.  
  82.         GetPort(curPort);
  83.         oldFont := curPort^.txFont;
  84.         oldSize := curPort^.txSize;
  85.         oldStyle := curPort^.txFace;
  86.         TextFont(0);
  87.         TextSize(0);
  88.         TextFace([]);
  89.         with theMenu do
  90.             begin
  91.                 theRect := menuRect;
  92.                 OffsetRect(theRect, 2, 2);
  93.                 FrameRect(theRect);
  94.                 theRect := menuRect;
  95.                 EraseRect(theRect);
  96.                 theRect := menuRect;
  97.                 InsetRect(theRect, -1, -1);
  98.                 PenPat(QDGlobals^.black);
  99.                 FrameRect(theRect);
  100.                 GetItem(menuH, last, theStr);
  101.                 MoveTo(menuRect.left + 14, menuRect.top + 12);
  102.                 GetItemStyle(menuH, last, theStyle);
  103.                 TextFace(theStyle);
  104.                 DrawString(Strip2Size(theStr, menuRect.right - menuRect.left - 15));
  105.                 if drawTitle then
  106.                     begin
  107.                         TextFace([]);
  108.                         theStr := menuH^^.menuData;
  109.                         MoveTo(menuRect.left - StringWidth(theStr) - 3, menuRect.top + 12);
  110.                         DrawString(theStr);
  111.                     end;
  112.             end;
  113.         TextFont(oldFont);
  114.         TextSize(oldSize);
  115.         TextFace(oldStyle);
  116.  
  117.     end; { UpdateMenu }
  118.  
  119. {----------------------------------------------}
  120.  
  121.     function PopSelect2 (var theMenu: PopMenu2): Integer;
  122.  
  123.         var
  124.             thePoint: Point;
  125.             result: Longint;
  126.             oldResFile: Integer;
  127.  
  128.     begin
  129.  
  130.         oldResFile := CurResFile;
  131.         PopSelect2 := 0;
  132.         with theMenu do
  133.             begin
  134.                 BitClr(Ptr(HiliteMode), pHiliteBit);
  135.                 InvertRect(titleRect);
  136.                 thePoint := menuRect.topLeft; { topLeft }
  137.                 LocalToGlobal(thePoint);
  138.                 if menuH <> nil then
  139.                     begin
  140.                         CheckItem(menuH, last, true);
  141.                         result := PopupMenuSelect(menuH, thePoint.V, thePoint.H, last);
  142.                         CheckItem(menuH, last, false);
  143.                         BitClr(Ptr(HiliteMode), pHiliteBit);
  144.                         InvertRect(titleRect);
  145.                         if (result <> 0) and (LoWord(result) <> last) then
  146.                             begin
  147.                                 last := LoWord(result);
  148.                                 PopSelect2 := last;
  149.                                 UpdateMenu2(theMenu, false);
  150.                             end;
  151.                     end;
  152.             end;
  153.         UseResFile(oldResFile);
  154.  
  155.     end; { PopSelect2 }
  156.  
  157. end.